package com.yy.job.core.dataprocess;

import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.yy.job.core.domain.JobDomain;
import com.yy.job.core.run.worker.ModuleWorker;

/**
 * 本地job处理器，提交的任务第一次执行在本机<br>
 * 此功能建议在分布式的测试环境使用，不建议在生产使用
 * 
 * @author eleven.li
 *
 */
public class LocalJobDataProcess extends BatchJobDataProcess {
	
	private Logger log = LoggerFactory.getLogger(LocalJobDataProcess.class);
	
	public LocalJobDataProcess(ModuleWorker jobBoss) {
		super(jobBoss);
	}
	
	@Override
	public void execute(int runCount) {
		log.info("start LocalJobDataProcess, moduleWorker name={}", this.moduleWorker.getModuleWorkerName());
		
		if(CollectionUtils.isEmpty(this.moduleWorker.getLocalJobQueue())) {
			return;
		}
		
		// 本机提交的本机执行任务
		while(CollectionUtils.isNotEmpty(this.moduleWorker.getLocalJobQueue())) {
			JobDomain poll = this.moduleWorker.getLocalJobQueue().poll();
			if(poll == null) {
				break;
			}
			this.moduleWorker.assignJobToWoker(poll);
		}
		
		log.info("end LocalJobDataProcess, moduleWorker name={}", this.moduleWorker.getModuleWorkerName());
	}

}
